// decryptdata.js

// Gaurav Dubey

// CSCI 5471 project

// Fall 2007


// This function decrypts the data that's returned from the server, and outputs it.

function decrypt()
{
	//Retrieve all the variables.
	var n = document.getElementById("n").value;
	n = n.replace(/\n/, "");
	var e = document.getElementById("e").value;
	e = e.replace(/\n/, "");
	var d = document.getElementById("d").value;
	d = d.replace(/\n/, "");
	var p = document.getElementById("p").value;
	p = p.replace(/\n/, "");
	var q = document.getElementById("q").value;
	q = q.replace(/\n/, "");
	var dmp1 = document.getElementById("dmp1").value;
	dmp1 = dmp1.replace(/\n/, "");
	var dmq1 = document.getElementById("dmq1").value;
	dmq1 = dmq1.replace(/\n/, "");
	var coeff = document.getElementById("coeff").value;
	coeff = coeff.replace(/\n/, "");
	var encryptedBFKey = document.getElementById("bfkey").value;
	encryptedBFKey = encryptedBFKey.replace(/\n/, "");
	
	//alert("e: " + e + "\nn: " + n);
	//alert("d: "+ d + "\np: " + p +"\nq: " + q + "\ndmp1: " + dmp1 + "\ndmq1: " + dmq1 + "\ncoeff: " + coeff);
	//alert("bfkey: " + encryptedBFKey);
	
	//Create an RSA key and decrypt the blowfish key.
	var rsa = new RSAKey();
	rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff);
	var bfKey = rsa.decrypt(encryptedBFKey);
	
	//alert(bfKey);
	
	//Next: use the Blowfish key to decrypt the data.
	var dataField = document.getElementById("data");
	var bf = new Blowfish(bfKey);
	dataField.value = bf.decrypt(dataField.value);
}